#!/usr/bin/env python
# -*- coding:utf-8 -*-

from flask_restful import Resource, reqparse
from flask import jsonify

from service.fileTeacherGradeService import FileTeacherGradeService
from utils import commons
from utils.response_code import RET


class FileTeacherGradeOtherResource(Resource):

    @classmethod
    def joint_query(cls):
        parser = reqparse.RequestParser()
        parser.add_argument('experiment_id', location='args', required=False, help='experiment_id参数类型不正确或缺失')
        parser.add_argument('teacher_grade', location='args', required=False, help='teacher_grade参数类型不正确或缺失')
        parser.add_argument('experiment_name', location='args', required=False, help='experiment_name参数类型不正确或缺失')
        parser.add_argument('student_name', location='args', required=False, help='student_name参数类型不正确或缺失')
        parser.add_argument('student_id', location='args', required=False, help='student_id参数类型不正确或缺失')
        parser.add_argument('teacher_id', location='args', required=False, help='teacher_id参数类型不正确或缺失')
        parser.add_argument('lesson_name', location='args', required=False, help='lesson_name参数类型不正确或缺失')
        parser.add_argument('file', location='args', required=False, help='file参数类型不正确或缺失')

        parser.add_argument('Page', location='args', required=False, help='Page参数类型不正确或缺失')
        parser.add_argument('Size', location='args', required=False, help='Size参数类型不正确或缺失')

        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)

        res = FileTeacherGradeService.joint_query(**kwargs)
        for item in res['data']:
            if item['file'] is not None:
                item['file'] = item['file'].decode()
        if res['code'] == RET.OK:
            return jsonify(code=res['code'], message=res['message'], data=res['data'], totalCount=res['totalCount'],
                           totalPage=res['totalPage'])
        else:
            return jsonify(code=res['code'], message=res['message'], data=res['data'])
